<%@ page pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<div class="r_location">
	<i class="r_txtico"></i> 门户通知管理
</div>
<div>
	<form id="uForm" action="">
		<ul class="all_list">
			<li>
				<span class="all_title">创建日期：</span>
				<span>
					<!-- <input type="text" class=" Wdate" id="beginTime" name="startDate" value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endTime\')}'})"> -
					<input type="text" class=" Wdate" id="endTime" name="endDate" value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'beginTime\')}'})"> -->
					<input type="text" id="beginTime" name="startDate" class="ui_input datepicker Wdate" group='{"group": {"startId":"beginTime", "endId":"endTime","showNext": true}}' option='start-auto-end' /> - <input type="text" id="endTime" name="endDate"  class="ui_input datepicker Wdate" option='start-auto-end'/>
				</span>
				<span class="m-l15"> 
					<input class="search_btn m-r15 submitBtn" type="button" value="查 询" id="subbtn">
					<input id="reset" class="reset_btn" type="reset" name="button" value="重 置">
				</span>
			</li>
		</ul>
		<div class="clearfix table_fn">
			<span class="l">门户通知列表 </span>
			<span class="r" style="_margin-top: 5px;">
				<shiro:hasPermission name="portalnotification:add">
					<a id="add_term" class="add_ico" onclick="addDialog()" title="" href="javascript:void(0)">新增</a>
				</shiro:hasPermission> 
			</span>
		</div>
		<table id="gridTable"></table>
		<div id="pgtoolbar1"></div>
	</form>
</div>

<script type="text/javascript">
$.datepicker();
var myDialog1,myDialog2,myDialog3;
$(function(){
	
	var colModel = [
	    			{
	    				label:'通知标题',
	    				name : 'title',
	    				width : 80,
	    				align: 'left',
	    				formatter: function(value,options,row){
	    					var result = "";
	    					<shiro:hasPermission name="portalnotification:detail">
	    						result += '<a href="#" onclick="show_detail(\''+row.id+'\')">'+value+'</a>';
	    					</shiro:hasPermission> 
	    					return result;
	    				}
	    			},
	    		/* 	 {
	    				label:'通知内容',
	    				name : 'content',
	    				index : 'content',
	    				width : 220,
	    				align: 'left',
	    				formatter: function(value,options,row){
	    					return '<a href="#" onclick="show_detail(\''+row.id+'\')">'+(value.trim()).substring(0,15)+'</a>';
	    					return result;
	    				}
	    			}, */ 
	    			{
	    				label:'创建日期',
	    				name : 'createTime',
	    				width : 80,
	    				formatter : to_date
	    			},
	    			{
						label:'有效时间',
						name : 'beginTime',
						width : 120,
						formatter: to_date,
						sortable : false,
						formatter : function(value, options, row) {
							return to_date_hms(row.beginTime) + ' 至 ' + to_date_hms(row.endTime);
						}
					},
	    			{
	    				label:'操作',
	    				name : 'oper',
	    				width : 60,
	    				formatter : function(value, options, row) {
	    					var result = '<span notesId="' + row.id + '">';
	    					<shiro:hasPermission name="portalnotification:update">
	    						result += '<a class="modify" href="">修改</a> ';
	    					</shiro:hasPermission> 
	    					<shiro:hasPermission name="portalnotification:delete">
	    						result += '<a class="delete" href="">删除</a>';
	    					</shiro:hasPermission> 
	    						result += '</span>';
	    					return result;
	    				},
	    				sortable : false
	    			} ];
	
	
	/*
	 * 查询结果表格
	 */
	var $grid = $('#gridTable');
	$grid.jqGrid({
		url : 'portalnotification/query/view',
		datatype : 'json',
		autowidth: true,
		rownumbers : true,
		height : 370,
		colModel: colModel,
		viewrecords : true,
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		jsonReader : {
			root : 'data.data',
			page : 'data.index',
			total : 'data.total',
			records : 'data.totalRecord',
			id : 'data.id',
			repeatitems : false
		},
		pager : '#pgtoolbar1',
		loadComplete : function(data) {
			if (data != null) {
				
				
			//alert("11");
			if (data.code == "01") {
           		art.dialog({icon: data.success,content: data.message,lock:true});
           		return;
           	}
			
			
			// 修改
			$grid.find('a.modify').click(function(){
				var notesId = $(this).parent().attr('notesId');
				myDialog2 = art.dialog({
					title : "门户通知修改",
					padding : "20px 60px 20px 60px",
					width:700,
   					lock : true
				});
				$.post('portalnotification/modify/page', {notesId : notesId}, function(data){
					myDialog2.content(data);
				});
				return false;
			
			});
			
			// 删除
			$grid.find('a.delete').click(function(){
				var notesId = $(this).parent().attr('notesId');
				art.dialog({
					title : '删除门户通知',
					lock : true,
					content : '确认删除?',
					width : '200px',
				    cancelVal: '关闭',
				    cancel: true,
					ok : function () {
						$.post('portalnotification/delete', {notesId : notesId}, function(data){
							if (data.success == 'succeed') {
								search(false);
							} else {
								art.dialog({icon: data.success,content: data.message,lock:true});
							}
						});
					}
				});
				return false;
			});	
				
				
			}
		}
	});
	

	
	
	var search = function() {		
		var param = {};
		var paramArray = $('#uForm').serializeArray();
		for (var i in paramArray) {
			param[paramArray[i].name] = paramArray[i].value;
		}
		
		var postData = $grid.jqGrid('getGridParam', 'postData');
		$.extend(postData, param);
		$grid.jqGrid("setGridParam",{datatype : 'json'}).trigger("reloadGrid",  [ {page : 1} ] );
	};

	$('#uForm').validator({}, {
		callback : function(results) {
			search();
		}
	});
	
	//search();
	

});

//查看通知详细
function show_detail(id){
	myDialog1 = art.dialog({
		title : "门户通知详情",
		width : 600,
		padding : "20px 60px 20px 60px"
	});
	$.post("portalnotification/detail", {notesId:id}, function(data) {
		myDialog1.content(data);
	});
	return false;
};

//新增门户通知
function addDialog() {
	showDialog('portalnotification/add/page?1=1', {
		title : '新增门户通知',
		lock : true,
		width:700
		
	});
}

function showDialog(url, options) {
	myDialog = art.dialog(options);// 初始化一个带有loading图标的空对话框
	jQuery.ajax({
		url : url + '&rand=' + Math.random(),
		success : function(data) {
			myDialog.content(data);// 填充对话框内容
		}
	});
}

</script>